/*
 * CategoriesDetailForm_View.java
 * Dibuat untuk percontohan final project mata kuliah
 * Pemrograman Lanjut yang diampu oleh M. Fairul Filza, M.Kom
 * STMIK AMIKOM Yogyakarta Tempat Kuliah Orang Berdasi
 * Created on 21 Oct 2013, 08:45:19
 */

package Views;

// <editor-fold defaultstate="collapsed" desc="Import Code">
import Controllers.Transaction_Controller;
import Interfaces.ViewsProcess_Interface;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
// </editor-fold>

/** @author FaiFilza@Amikom.ac.id */
public class Transaction_EditView extends JPanel implements ViewsProcess_Interface {
    // Class Attribute
    private ImageIcon Image;

    // <editor-fold defaultstate="collapsed" desc="Layout Attribute">
    // Initialize Component Panel
    
    private JLabel LblWallpaper;
    private JTextField TxtCdId;
    private JTextField TxtTitle;
    private JTextField TxtPrice;
    private JTextField TxtBanyak;
    private JTextField TxtTotal;
    private JTextField TxtCash;
    private JTextField TxtChange;
    private JTextField TxtCode;
    private JTextField TxtStock;
    
    private JLabel LblTotal;
    
    private JButton BtnEdit;
    private JButton BtnDelete;
    private JButton BtnAdd;
    private JButton BtnOk;
    private JButton BtnCancel;
    private JScrollPane ScrTable;
    private JTable TblDetail;
    private String num;
    
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructor Code">
    public Transaction_EditView() {
        LblWallpaper = new JLabel();
        TxtCdId = new JTextField();
        TxtTitle = new JTextField();
        TxtPrice = new JTextField();
        TxtBanyak = new JTextField();
        TxtTotal = new JTextField();
        TxtCash = new JTextField();
        TxtChange = new JTextField();
        BtnEdit = new JButton();
        BtnDelete = new JButton();
        BtnAdd = new JButton();
        BtnOk = new JButton();
        BtnCancel = new JButton();
        ScrTable = new JScrollPane();
        TblDetail = new JTable();
        TxtCode = new JTextField();
        TxtStock = new JTextField();
        LblTotal = new JLabel();
        num = "";
        initComponents();
    }

    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Getter and Setter Code">

    public JTextField getTxtStock() {
        return TxtStock;
    }

    public void setTxtStock(JTextField TxtStock) {
        this.TxtStock = TxtStock;
    }

    public JLabel getLblTotal() {
        return LblTotal;
    }

    public void setLblTotal(JLabel LblTotal) {
        this.LblTotal = LblTotal;
    }
    
    
    public JLabel getLblWallpaper(){
        return LblWallpaper;
    }
    public void setLblWallpaper(JLabel LblWallpaper){
        this.LblWallpaper = LblWallpaper;
    }
    public JTextField getTxtCdId(){
        return TxtCdId;
    }
    public void setTxtCdId(JTextField TxtCdId){
        this.TxtCdId = TxtCdId;
    }
    public JTextField getTxtTitle(){
        return TxtTitle;
    }
    public void setTxtTitle(JTextField TxtTitle){
        this.TxtTitle = TxtTitle;
    }
    public JTextField getTxtPrice(){
        return TxtPrice;
    }
    public void setTxtPrice(JTextField TxtPrice){
        this.TxtPrice = TxtPrice;
    }
    public JTextField getTxtBanyak(){
        return TxtBanyak;
    }
    public void setTxtBanyak(JTextField TxtBanyak){
        this.TxtBanyak = TxtBanyak;
    }
    public JTextField getTxtTotal(){
        return TxtTotal;
    }
    public void setTxtTotal(JTextField TxtTotal){
        this.TxtTotal = TxtTotal;
    }
    public JTextField getTxtCash(){
        return TxtCash;
    }
    public void setTxtCash(JTextField TxtCash){
        this.TxtCash = TxtCash;
    }
    public JTextField getTxtChange(){
        return TxtChange;
    }
    public void setTxtChange(JTextField TxtChange){
        this.TxtChange = TxtChange;
    }

    public JTextField getTxtCode() {
        return TxtCode;
    }

    public void setTxtCode(JTextField TxtCode) {
        this.TxtCode = TxtCode;
    }
    
    public JButton getBtnEdit(){
        return BtnEdit;
    }
    public void setBtnEdit(JButton BtnEdit){
        this.BtnEdit = BtnEdit;
    }
    public JButton getBtnDelete(){
        return BtnDelete;
    }
    public void setBtnDelete(JButton BtnDelete){
        this.BtnDelete = BtnDelete;
    }
    public JButton getBtnAdd(){
        return BtnAdd;
    }
    public void setBtnAdd(JButton BtnAdd){
        this.BtnAdd = BtnAdd;
    }
    public JButton getBtnOk(){
        return BtnOk;
    }
    public void setBtnOk(JButton BtnOk){
        this.BtnOk = BtnOk;
    }
    
    public JScrollPane getScrTable() {
        return ScrTable;
    }

    public void setScrTable(JScrollPane ScrTable) {
        this.ScrTable = ScrTable;
    }

    public JTable getTblDetail() {
        return TblDetail;
    }

    public void setTblDetail(JTable TblDetail) {
        this.TblDetail = TblDetail;
    }

    public JButton getBtnCancel() {
        return BtnCancel;
    }

    public void setBtnCancel(JButton BtnCancel) {
        this.BtnCancel = BtnCancel;
    }

    public String getNum() {
        return num;
    }

    public void setNum(String num) {
        this.num = num;
    }
    
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Method Code">
    private void createKeybindings(JTable table) {
        table.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "Enter");
        table.getActionMap().put("Enter", new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                //do something on JTable enter pressed
            }
        });
    }
//    public JPanel pnlEntities() {
//        JPanel Panel = new JPanel();
//        Font FontStyle = new Font("Tahoma", 1, 12);
//
//        Panel.setLayout(null);
//        Panel.setBackground(new Color(0, 0, 0));
//        Panel.setOpaque(true);
//
//        
//
//        
//        TblDetail.setModel(new javax.swing.table.DefaultTableModel(
//            new Object [][] {
//
//            },
//            new String [] {
//
//            }
//        ));
//        ScrTable.setViewportView(TblDetail);
//        Panel.add(ScrTable);
//        ScrTable.setBounds(144, 205, 837, 192);
//
//        
//
//        
//        TxtCdId.setOpaque(true);
//        TxtCdId.setBorder(null);
//        TxtCdId.setHorizontalAlignment(JLabel.LEADING);
//        TxtCdId.setFont(FontStyle);
//        Panel.add(TxtCdId);
//        TxtCdId.setBounds(156,178,117,19);
//        
//        TxtTitle.setOpaque(true);
//        TxtTitle.setBorder(null);
//        TxtTitle.setHorizontalAlignment(JLabel.LEADING);
//        TxtTitle.setEditable(false);
//        TxtTitle.setFont(FontStyle);
//        Panel.add(TxtTitle);
//        TxtTitle.setBounds(293,178,264,19);
//        
//        TxtPrice.setOpaque(true);
//        TxtPrice.setBorder(null);
//        TxtPrice.setHorizontalAlignment(JLabel.LEADING);
//        TxtPrice.setEditable(false);
//        TxtPrice.setFont(FontStyle);
//        Panel.add(TxtPrice);
//        TxtPrice.setBounds(702,178,182,19);
//        
//        TxtBanyak.setOpaque(true);
//        TxtBanyak.setBorder(null);
//        TxtBanyak.setHorizontalAlignment(JLabel.LEADING);
//        TxtBanyak.setFont(FontStyle);
//        Panel.add(TxtBanyak);
//        TxtBanyak.setBounds(578,178,100,19);
//        
//        TxtTotal.setOpaque(true);
//        TxtTotal.setBorder(null);
//        TxtTotal.setHorizontalAlignment(JLabel.LEADING);
//        TxtTotal.setFont(FontStyle);
//        TxtTotal.setVisible(false);
//        Panel.add(TxtTotal);
//        TxtTotal.setBounds(792, 410, 187, 35);
//        
//        LblTotal.setFont(new Font("Harrington", 1, 36));
//        LblTotal.setHorizontalAlignment(JLabel.RIGHT);
//        Panel.add(LblTotal);
//        LblTotal.setBounds(792, 410, 187, 35);
//
//        
//        TxtCash.setOpaque(true);
//        TxtCash.setBorder(null);
//        TxtCash.setHorizontalAlignment(JLabel.LEADING);
//        TxtCash.setFont(FontStyle);
//        Panel.add(TxtCash);
//        TxtCash.setBounds(792, 466, 187, 15);
//        
//        TxtChange.setOpaque(true);
//        TxtChange.setBorder(null);
//        TxtChange.setHorizontalAlignment(JLabel.LEADING);
//        TxtChange.setFont(FontStyle);
//        Panel.add(TxtChange);
//        TxtChange.setBounds(792, 500, 187, 15);
//        
//        TxtCode.setOpaque(true);
//        TxtCode.setBorder(null);
//        TxtCode.setHorizontalAlignment(JLabel.LEADING);
//        TxtCode.setFont(FontStyle);
//        Panel.add(TxtCode);
//        TxtCode.setVisible(false);
//        TxtCode.setBounds(0, 0, 309, 22);
//        
//        TxtStock.setOpaque(true);
//        TxtStock.setBorder(null);
//        TxtStock.setHorizontalAlignment(JLabel.LEADING);
//        TxtStock.setFont(FontStyle);
//        Panel.add(TxtStock);
//        TxtStock.setVisible(false);
//        TxtStock.setBounds(145, 11, 309, 22);
//        
//        BtnAdd.setOpaque(false);
//        BtnAdd.setBorderPainted(false);
//        BtnAdd.setContentAreaFilled(false);
//        BtnAdd.setBorder(null);
//        BtnAdd.setVisible(true);
//        Panel.add(BtnAdd);
//        BtnAdd.setBounds(890,178,69,21);
//        
//        BtnEdit.setOpaque(false);
//        BtnEdit.setBorderPainted(false);
//        BtnEdit.setContentAreaFilled(false);
//        BtnEdit.setBorder(null);
//        BtnEdit.setEnabled(false);
//        BtnEdit.setVisible(true);
//        Panel.add(BtnEdit);
//        BtnEdit.setBounds(7,272,118,35);
//        
//        BtnDelete.setOpaque(false);
//        BtnDelete.setBorderPainted(false);
//        BtnDelete.setContentAreaFilled(false);
//        BtnDelete.setBorder(null);
//        BtnDelete.setEnabled(false);
//        BtnDelete.setVisible(true);
//        Panel.add(BtnDelete);
//        BtnDelete.setBounds(7,325,118,35);
//        
//        BtnOk.setOpaque(false);
//        BtnOk.setBorderPainted(false);
//        BtnOk.setContentAreaFilled(false);
//        BtnOk.setBorder(null);
//        BtnOk.setVisible(!true);
//        Panel.add(BtnOk);
//        BtnOk.setBounds(792,525,118,35);
//        
//        BtnCancel.setOpaque(false);
//        BtnCancel.setBorderPainted(false);
//        BtnCancel.setContentAreaFilled(false);
//        BtnCancel.setBorder(null);
//        BtnCancel.setVisible(!true);
//        Panel.add(BtnCancel);
//        BtnCancel.setBounds(664,525,118,35);
//        
//        Transaction_Controller ControlPanel = new Transaction_Controller(this);
//        Panel.addComponentListener(ControlPanel.EditComponent_Listener);
//        
//        // Context Panel
//        //Panel.setLayout(null);
//        //Panel.setBackground(new Color(0, 250, 250));
//        //Panel.setOpaque(true);
//        //Panel.setVisible(true);
//        //Panel.add(getPnlFront());
//        //Pael.setBounds(0, 0, 847, 402);
//
//        getLblWallpaper().setText(null);
//        getLblWallpaper().setBackground(new Color(250, 0, 250));
//        getLblWallpaper().setOpaque(false);
//        Panel.add(getLblWallpaper());
//        getLblWallpaper().setBounds(139, 163, 847, 402);
//
//        eventControllers();
//        imageControllers();
//        return Panel;
//    }

    @Override
    public void eventControllers() {
        
        Transaction_Controller ControlPanel = new Transaction_Controller(this);
        this.addComponentListener(ControlPanel.EditComponent_Listener);
        //pnlEntities().addComponentListener(ControlPanel.EditComponent_Listener);
        BtnAdd.addActionListener(ControlPanel.EditButton_Listener);
        BtnEdit.addActionListener(ControlPanel.EditButton_Listener);
        BtnOk.addActionListener(ControlPanel.EditButton_Listener);
        BtnCancel.addActionListener(ControlPanel.EditButton_Listener);
        BtnEdit.addMouseListener(ControlPanel.EditButtonImg_Listener);
        BtnDelete.addActionListener(ControlPanel.EditButton_Listener);
        BtnDelete.addMouseListener(ControlPanel.EditButtonImg_Listener);
        TblDetail.addKeyListener(ControlPanel.EditKey_Listener);
        TxtCdId.addKeyListener(ControlPanel.EditKey_Listener);
        TxtBanyak.addKeyListener(ControlPanel.EditKey_Listener);
        TxtCash.addKeyListener(ControlPanel.EditKey_Listener);
        TblDetail.addMouseListener(ControlPanel.EditTable_Listener);
        createKeybindings(TblDetail);
    }

    @Override
    public void imageControllers() {
        Image = new ImageIcon(getClass().getResource("/Images/Transaction_frame2_1.png"));
        LblWallpaper.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/edit3.png"));
        BtnEdit.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/delete3.png"));
        BtnDelete.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/add.png"));
        BtnAdd.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/OK3.png"));
        BtnOk.setIcon(Image);
        Image = new ImageIcon(getClass().getResource("/Images/cancel4.png"));
        BtnCancel.setIcon(Image);
    }
    // </editor-fold>

    @Override
    public void initComponents() {
        //JPanel Panel = new JPanel();
        Font FontStyle = new Font("Tahoma", 1, 12);

        this.setLayout(null);
        this.setBackground(new Color(0, 0, 0));
        this.setOpaque(true);

        

        
        TblDetail.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        ScrTable.setViewportView(TblDetail);
//        ScrTable.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(ScrTable);
        ScrTable.setBounds(144, 212, 840, 191);

        

        
        TxtCdId.setOpaque(true);
        TxtCdId.setBorder(null);
        TxtCdId.setHorizontalAlignment(JLabel.LEADING);
        TxtCdId.setFont(FontStyle);
        this.add(TxtCdId);
        TxtCdId.setBounds(156,184,117,19);
        
        TxtTitle.setOpaque(true);
        TxtTitle.setBorder(null);
        TxtTitle.setHorizontalAlignment(JLabel.LEADING);
        TxtTitle.setEditable(false);
        TxtTitle.setFont(FontStyle);
        this.add(TxtTitle);
        TxtTitle.setBounds(293,184,266,19);
        
        TxtPrice.setOpaque(true);
        TxtPrice.setBorder(null);
        TxtPrice.setHorizontalAlignment(JLabel.LEADING);
        TxtPrice.setEditable(false);
        TxtPrice.setFont(FontStyle);
        this.add(TxtPrice);
        TxtPrice.setBounds(700,184,184,19);
        
        TxtBanyak.setOpaque(true);
        TxtBanyak.setBorder(null);
        TxtBanyak.setHorizontalAlignment(JLabel.LEADING);
        TxtBanyak.setFont(FontStyle);
        this.add(TxtBanyak);
        TxtBanyak.setBounds(578,184,100,19);
        
        TxtTotal.setOpaque(true);
        TxtTotal.setBorder(null);
        TxtTotal.setHorizontalAlignment(JLabel.LEADING);
        TxtTotal.setFont(FontStyle);
        TxtTotal.setVisible(false);
        this.add(TxtTotal);
        TxtTotal.setBounds(792, 410, 187, 35);
        
        LblTotal.setFont(new Font("Tahoma", 0, 36));
        LblTotal.setHorizontalAlignment(JLabel.RIGHT);
        this.add(LblTotal);
        LblTotal.setBounds(792, 417, 187, 35);

        
        TxtCash.setOpaque(true);
        TxtCash.setBorder(null);
        TxtCash.setHorizontalAlignment(JLabel.RIGHT);
        TxtCash.setFont(FontStyle);
        this.add(TxtCash);
        TxtCash.setBounds(792, 473, 187, 15);
        
        TxtChange.setOpaque(true);
        TxtChange.setBorder(null);
        TxtChange.setHorizontalAlignment(JLabel.RIGHT);
        TxtChange.setFont(FontStyle);
        this.add(TxtChange);
        TxtChange.setBounds(792, 507, 187, 15);
        
        TxtCode.setOpaque(true);
        TxtCode.setBorder(null);
        TxtCode.setHorizontalAlignment(JLabel.LEADING);
        TxtCode.setFont(FontStyle);
        this.add(TxtCode);
        TxtCode.setVisible(false);
        TxtCode.setBounds(0, 0, 309, 22);
        
        TxtStock.setOpaque(true);
        TxtStock.setBorder(null);
        TxtStock.setHorizontalAlignment(JLabel.LEADING);
        TxtStock.setFont(FontStyle);
        this.add(TxtStock);
        TxtStock.setVisible(false);
        TxtStock.setBounds(145, 11, 309, 22);
        
        BtnAdd.setOpaque(false);
        BtnAdd.setBorderPainted(false);
        BtnAdd.setContentAreaFilled(false);
        BtnAdd.setBorder(null);
        BtnAdd.setVisible(true);
        BtnAdd.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnAdd);
        BtnAdd.setBounds(890,183,69,21);
        
        BtnEdit.setOpaque(false);
        BtnEdit.setBorderPainted(false);
        BtnEdit.setContentAreaFilled(false);
        BtnEdit.setBorder(null);
        BtnEdit.setEnabled(false);
        BtnEdit.setVisible(true);
        BtnEdit.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnEdit);
        BtnEdit.setBounds(7,272,118,35);
        
        BtnDelete.setOpaque(false);
        BtnDelete.setBorderPainted(false);
        BtnDelete.setContentAreaFilled(false);
        BtnDelete.setBorder(null);
        BtnDelete.setEnabled(false);
        BtnDelete.setVisible(true);
        BtnDelete.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnDelete);
        BtnDelete.setBounds(7,325,118,35);
        
        BtnOk.setOpaque(false);
        BtnOk.setBorderPainted(false);
        BtnOk.setContentAreaFilled(false);
        BtnOk.setBorder(null);
        BtnOk.setVisible(!true);
        BtnOk.setEnabled(false);
        BtnOk.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnOk);
        BtnOk.setBounds(664,531,118,35);
        
        BtnCancel.setOpaque(false);
        BtnCancel.setBorderPainted(false);
        BtnCancel.setContentAreaFilled(false);
        BtnCancel.setBorder(null);
        BtnCancel.setVisible(!true);
        BtnCancel.setEnabled(false);
        BtnCancel.setCursor(new Cursor(Cursor.HAND_CURSOR));
        this.add(BtnCancel);
        BtnCancel.setBounds(792,531,118,35);
        
        Transaction_Controller ControlPanel = new Transaction_Controller(this);
        this.addComponentListener(ControlPanel.EditComponent_Listener);
        
        // Context Panel
        //Panel.setLayout(null);
        //Panel.setBackground(new Color(0, 250, 250));
        //Panel.setOpaque(true);
        //Panel.setVisible(true);
        //Panel.add(getPnlFront());
        //Pael.setBounds(0, 0, 847, 402);

        getLblWallpaper().setText(null);
        getLblWallpaper().setBackground(new Color(250, 0, 250));
        getLblWallpaper().setOpaque(false);
        this.add(getLblWallpaper());
        getLblWallpaper().setBounds(139, 163, 853, 416);

        eventControllers();
        imageControllers();
    }
}